package com.example.demo.service;

import com.example.demo.dao.UserMapper;
import com.example.demo.entity.BaseResponse;
import com.example.demo.model.UserModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 业务逻辑层，虽然代码简单，但是大型项目，一般都有这些。
 */
@Service
public class UserService {

    @Resource
    private UserMapper userMapper;

    public String loginCheck(Integer id) {
        UserModel userModel = userMapper.selectById(id);
        if (userModel == null) {
            return "用户不存在";
        } else {
            return userModel.getUserName();
        }
    }

    public BaseResponse register(UserModel userModel) {
        int insert = userMapper.insert(userModel);
        if (insert > 0) {
            return new BaseResponse(200, "插入成功", null);
        } else {
            return new BaseResponse(500, "插入失败", null);
        }
    }

}
